<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/default}">
<head>
    <title>评价详情 - 废物回收管理系统</title>
    <style>
        .rating {
            color: #ffc107;
        }
        .rating-empty {
            color: #e9ecef;
        }
        .comment-card {
            background: #f8f9fa;
            border-radius: 0.5rem;
            padding: 1.5rem;
            margin-bottom: 1rem;
        }
        .reply-card {
            background: #fff;
            border: 1px solid #dee2e6;
            border-radius: 0.5rem;
            padding: 1.5rem;
            margin-top: 1rem;
        }
        .user-info {
            display: flex;
            align-items: center;
            margin-bottom: 1rem;
        }
        .user-avatar {
            width: 48px;
            height: 48px;
            border-radius: 50%;
            background: #e9ecef;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 1rem;
        }
        .comment-content {
            margin: 1rem 0;
            font-size: 1.1rem;
        }
        .meta-info {
            color: #6c757d;
            font-size: 0.9rem;
        }
    </style>
</head>
<body>
    <div layout:fragment="content">
        <div class="container-fluid">
            <!-- 返回按钮和标题 -->
            <div class="d-flex align-items-center mb-4">
                <a href="/evaluation/list" class="btn btn-link">
                    <i class="fas fa-arrow-left"></i> 返回列表
                </a>
                <h4 class="mb-0 ms-2">评价详情</h4>
            </div>
            
            <!-- 订单信息 -->
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="card-title mb-0">订单信息</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-4">
                            <p class="mb-1">
                                <strong>订单号：</strong>
                                <a th:href="@{'/order/detail/' + ${evaluation.order.id}}" 
                                   th:text="${evaluation.order.orderNo}">ON2024030100001</a>
                            </p>
                        </div>
                        <div class="col-md-4">
                            <p class="mb-1">
                                <strong>回收物品：</strong>
                                <span th:text="${evaluation.order.itemType}">废纸</span>
                            </p>
                        </div>
                        <div class="col-md-4">
                            <p class="mb-1">
                                <strong>回收重量：</strong>
                                <span th:text="${evaluation.order.actualWeight + ' kg'}">10.5 kg</span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 评价内容 -->
            <div class="comment-card">
                <div class="user-info">
                    <div class="user-avatar">
                        <i class="fas fa-user"></i>
                    </div>
                    <div>
                        <h6 class="mb-0" th:text="${evaluation.user.realName}">张三</h6>
                        <div class="rating">
                            <th:block th:each="i : ${#numbers.sequence(1, 5)}">
                                <i class="fas fa-star" 
                                   th:classappend="${i <= evaluation.rating} ? '' : 'rating-empty'"></i>
                            </th:block>
                        </div>
                    </div>
                </div>
                <div class="comment-content" th:text="${evaluation.comment}">
                    服务态度很好，准时上门回收，称重也很准确。
                </div>
                <div class="meta-info">
                    <i class="far fa-clock"></i>
                    <span th:text="${#temporals.format(evaluation.commentTime, 'yyyy-MM-dd HH:mm')}">
                        2024-03-01 10:00
                    </span>
                </div>
                
                <!-- 回复内容 -->
                <div class="reply-card" th:if="${evaluation.status == 1}">
                    <div class="user-info">
                        <div class="user-avatar">
                            <i class="fas fa-user-tie"></i>
                        </div>
                        <div>
                            <h6 class="mb-0" th:text="${evaluation.collector.realName}">李四</h6>
                            <small class="text-muted">回收员</small>
                        </div>
                    </div>
                    <div class="comment-content" th:text="${evaluation.reply}">
                        感谢您的评价，我们会继续保持优质服务。
                    </div>
                    <div class="meta-info">
                        <i class="far fa-clock"></i>
                        <span th:text="${#temporals.format(evaluation.replyTime, 'yyyy-MM-dd HH:mm')}">
                            2024-03-01 11:00
                        </span>
                    </div>
                </div>
                
                <!-- 回复按钮 -->
                <div class="text-end mt-3" th:if="${role == 'ROLE_COLLECTOR' && evaluation.status == 0}">
                    <button class="btn btn-primary" onclick="showReplyModal()">
                        <i class="fas fa-reply"></i> 回复评价
                    </button>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 回复评价模态框 -->
    <div class="modal fade" id="replyModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">回复评价</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <form id="replyForm">
                        <div class="mb-3">
                            <label class="form-label">回复内容</label>
                            <textarea class="form-control" id="replyContent" rows="3" required></textarea>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="submitReply()">提交</button>
                </div>
            </div>
        </div>
    </div>
    
    <th:block layout:fragment="scripts">
        <script>
            // 显示回复模态框
            function showReplyModal() {
                document.getElementById('replyContent').value = '';
                new bootstrap.Modal(document.getElementById('replyModal')).show();
            }
            
            // 提交回复
            function submitReply() {
                const reply = document.getElementById('replyContent').value;
                
                if (!reply) {
                    showToast('error', '请输入回复内容');
                    return;
                }
                
                fetch(`/evaluation/${evaluation.id}/reply`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    body: `reply=${encodeURIComponent(reply)}`
                }).then(response => {
                    if (!response.ok) {
                        throw new Error('回复失败');
                    }
                    showToast('success', '回复成功');
                    setTimeout(() => window.location.reload(), 1000);
                }).catch(error => {
                    showToast('error', error.message);
                });
            }
        </script>
    </th:block>
</body>
</html> 